<html>
    <head>
        <title>XML 2 JSON</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
        <script src="resources/js/jquery.xml2json.js" type="text/javascript" language="javascript"></script>
        <script type="text/javascript">
            //../resources/xml/zero.xml
            //http://adressesok.posten.no/api/v1/postal_codes.xml?postal_code=0*
            
            $(function(){
                $.get("resources/xml/zero.xml",
                function(xml){
                    var json = $.xml2json(xml),
                        text = "",
                        postalCodes = json.postal_codes.postal_code;
                    console.log(json);
                    
                    for(var i = 0; i<postalCodes.length; i++){
                        var postalCode = postalCodes[i].postal_code,
                            name = postalCodes[i].city,
                            municipality = postalCodes[i].primary_municipality,
                            county = postalCodes[i].primary_county,
                            countryCode = "NO",
                            category = postalCodes[i].category;
                        text += "INSERT INTO place(postal_no, name, municipality, county, country_code, category) VALUES (";
                        text += "'" + postalCode + "', ";
                        text += "'" + name + "', ";
                        text += "'" + municipality + "', ";
                        text += "'" + county + "', ";
                        text += "'" + countryCode + "', ";
                        text += "'" + category + "'";
                        text += ");";
                        if(i !== (postalCodes.length - 1)){
                            text += "\n";
                        }
                    }
                    console.log(text);
                });
            });
        </script>
    </body>
</html>